﻿using System;
using System.Collections.Generic;
using System.Text;
using jnagr.DBUtility;
using System.Data.SqlClient;
using System.Data;

namespace jnagr.DAL
{
   public class PagedHelper
    {
        #region  扩展方法
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        /// <param name="PageSize">页尺寸</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="fldName">字段名</param>
        /// <param name="OrderType">设置排序类型, 非 0 值则降序</param>
        /// <param name="strWhere">查询条件 (注意: 不要加 where)</param>
        /// <returns></returns>
        public static DataSet GetList(string tblName,int PageSize, int PageIndex, string fldName, string OrderType, string strWhere)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
            parameters[0].Value = tblName;
            parameters[1].Value = fldName;
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 1;//返回记录总数, 非 0 值则返回
            parameters[5].Value = OrderType == "desc" ? 1 : 0;
            parameters[6].Value = strWhere;
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage", parameters, "ds");
        }

        #endregion
    }
}
